package com.buddy.learn.spring.framework.aop.aspect;

import com.buddy.learn.spring.framework.aop.intercept.BMethodInterceptor;
import com.buddy.learn.spring.framework.aop.intercept.BMethodInvocation;

import java.lang.reflect.Method;

public class BAfterAdviceInterceptor extends BAbstractAspectAdvice implements BMethodInterceptor {

    private BJoinPoint joinpoint;

    public BAfterAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    @Override
    public Object invoke(BMethodInvocation mi) throws Throwable {
        Object retVal = mi.proceed();
        this.afterReturning(retVal,mi.getMethod(),mi.getArguments(),mi.getThis());
        return retVal;
    }


    private void  afterReturning(Object retVal, Method method, Object[] arguments, Object aThis) throws Throwable {
        super.invokeAdviceMethod(this.joinpoint,retVal,null);
    }
}
